package com.forestar.mapControl.mapview.multitouch.listener;

import android.graphics.PointF;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.OnScaleGestureListener;

import com.forestar.mapControl.utils.LogD;


public class ScaleGestureDetectorListener implements OnScaleGestureListener
  {

//    private MapControl mapControl;
    private float lastFocusX;
    private float lastFocusY;
    private float currentScaleFactor;

    private float scaleSum;

//    public ScaleGestureDetectorListener(MapControl mapControl)
//      {
//        this.mapControl = mapControl;
//      }

    @Override
    public boolean onScale(ScaleGestureDetector detector)
      {
        try
          {
            currentScaleFactor = detector.getPreviousSpan() / detector.getCurrentSpan();
            scaleSum *= currentScaleFactor;
            float lastFocusX = detector.getFocusX();
            float lastFocusY = detector.getFocusY();
            PointF atPoint = new PointF(lastFocusX, lastFocusY);
//            if (mapControl.getCanTouchScrollOrScale())
//              {
            LogD.d("缩放执行中");
//                mapControl.zoomFastAt(atPoint, currentScaleFactor);
//              }
            //    GISLog.d(GISLog.GIS_LOG, this, "onScale", "双指缩放的频率");
          } catch (Exception e)
          {
            LogD.e(e.getMessage());
          }
        return true;
      }

    @Override
    public boolean onScaleBegin(ScaleGestureDetector detector)
      {
        LogD.d("开始执行缩放");
        scaleSum = 1;
        lastFocusX = detector.getFocusX();
        lastFocusY = detector.getFocusY();
        currentScaleFactor = 1.0f;
        return true;
      }

    @Override
    public void onScaleEnd(ScaleGestureDetector detector)
      {
        LogD.d("开始加载缩放后的地图");
//        mapControl.getGeoMap().refreshAsync();
      }
  }
